package com.aeroyun.macross.modular.countryside.controller;

import com.aeroyun.macross.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.aeroyun.macross.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.aeroyun.macross.modular.system.model.Expense;
import com.aeroyun.macross.modular.countryside.service.IExpenseService;

/**
 * 支出管理控制器
 *
 * @author fengshuonan
 * @Date 2018-08-10 16:18:15
 */
@Controller
@RequestMapping("/expense")
public class ExpenseController extends BaseController {

    private String PREFIX = "/countryside/expense/";

    @Autowired
    private IExpenseService expenseService;

    /**
     * 跳转到支出管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "expense.html";
    }

    /**
     * 跳转到添加支出管理
     */
    @RequestMapping("/expense_add")
    public String expenseAdd() {
        return PREFIX + "expense_add.html";
    }

    /**
     * 跳转到修改支出管理
     */
    @RequestMapping("/expense_update/{expenseId}")
    public String expenseUpdate(@PathVariable Integer expenseId, Model model) {
        Expense expense = expenseService.selectById(expenseId);
        model.addAttribute("item",expense);
        LogObjectHolder.me().set(expense);
        return PREFIX + "expense_edit.html";
    }

    /**
     * 获取支出管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return expenseService.selectList(null);
    }

    /**
     * 新增支出管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Expense expense) {
        expenseService.insert(expense);
        return SUCCESS_TIP;
    }

    /**
     * 删除支出管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer expenseId) {
        expenseService.deleteById(expenseId);
        return SUCCESS_TIP;
    }

    /**
     * 修改支出管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Expense expense) {
        expenseService.updateById(expense);
        return SUCCESS_TIP;
    }

    /**
     * 支出管理详情
     */
    @RequestMapping(value = "/detail/{expenseId}")
    @ResponseBody
    public Object detail(@PathVariable("expenseId") Integer expenseId) {
        return expenseService.selectById(expenseId);
    }
}
